﻿/* Template done by
 * 
 * Richard Clark
 * Project Hoshimi Lead Manager
 * Contact at ori@c2i.fr
 * 
*/
using System;
using System.Collections.Generic;
using System.Text;

using System.Drawing;
using VG.Common;
using VG.Map;

namespace hoshimiTest
{

    [Characteristics(ContainerCapacity = 20, CollectTransfertSpeed = 5, Scan = 5, MaxDamage = 0, DefenseDistance = 0, Constitution = 20)]
    public class Collector : VG.Common.NanoCollector, IActionable
    {

        public enum CollectorWhatToDoNextAction
        {
            NothingToDo,
            MoveToHoshimi,
            CollectAZN,
            AutoDestroy,
            TransferToNeedle,
            MoveToAZN
        }

        public const int SquadNumber = 0;
        public int m_turns_of_recollection = 4;
        private CollectorWhatToDoNextAction m_WhatToDoNext = CollectorWhatToDoNextAction.NothingToDo;

        private static char[] sep = { ',' };
        public Point HP_point;

        #region IAction Members
        
        
        // Acciones del collector.
        public void DoActions()
        {
            
            switch (this.m_WhatToDoNext)
            {
                case CollectorWhatToDoNextAction.NothingToDo:
                    this.HP_point = ((myPlayer)this.PlayerOwner).Needles[this.InternalName];
                    //this.m_WhatToDoNext = CollectorWhatToDoNextAction.MoveToAZN;
                    goto DirectAcces;
                    //break;
                case CollectorWhatToDoNextAction.CollectAZN:
                    this.CollectFrom(this.Location, m_turns_of_recollection);
                    this.m_WhatToDoNext = CollectorWhatToDoNextAction.MoveToHoshimi;
                    break;

                case CollectorWhatToDoNextAction.MoveToHoshimi:
                    //this.MoveTo(Utils.getNearestPoint(this.Location, ((myPlayer)this.PlayerOwner).HoshimiEntities));
                    this.MoveTo(HP_point);
                    this.m_WhatToDoNext = CollectorWhatToDoNextAction.TransferToNeedle;
                    break;

                case CollectorWhatToDoNextAction.TransferToNeedle:
                    this.TransferTo(this.Location, m_turns_of_recollection);
                    this.m_WhatToDoNext = CollectorWhatToDoNextAction.MoveToAZN;
                    break;

                case CollectorWhatToDoNextAction.MoveToAZN:
                    DirectAcces:
                    this.MoveTo(Utils.getNearestPoint(this.HP_point, ((myPlayer)this.PlayerOwner).AZNEntities));
                    this.m_WhatToDoNext = CollectorWhatToDoNextAction.CollectAZN;
                    break;
            }
        }

        public void SetTurnsOffRecollection(int _turns)
        {
            this.m_turns_of_recollection = _turns;
        }

        public int GetTurnsOfRecollection()
        {
            return this.m_turns_of_recollection;
        }


        #endregion
    }

    [Characteristics(ContainerCapacity = 100, CollectTransfertSpeed = 0, Scan = 0, MaxDamage = 0, DefenseDistance = 0, Constitution = 50)]
    public class Needle : VG.Common.NanoNeedle, IActionable
    {
        public const int SquadNumber = 0;
        #region IAction Members
        public void DoActions()
        { }
        #endregion
    }

    [Characteristics(ContainerCapacity = 0, CollectTransfertSpeed = 0, Scan = 30, MaxDamage = 0, DefenseDistance = 0, Constitution = 10)]
    public class Explorer : VG.Common.NanoExplorer, IActionable
    {
        public enum WhatToDoNextAction
        {
            WaitingForPoints,
            MoveToPoint,
            Attack,
            WaitingForAttackPoints,

        }
        public WhatToDoNextAction WhatToDoNext=WhatToDoNextAction.WaitingForPoints; 
        private Queue<Point> m_PointsToVisit = new Queue<Point>();
        private Queue<Point> m_PointsToAttack = new Queue<Point>();

        public Queue<Point> PointsToVisit
        {
            get { return m_PointsToVisit; }
        }

        public Queue<Point> PointsToAttack
        {
            get { return m_PointsToAttack; }
        }

        public void DoActions()
        {
            switch (this.WhatToDoNext)
            {
                case WhatToDoNextAction.WaitingForPoints:
                    break;

                // exploracion.
                case WhatToDoNextAction.MoveToPoint:
                    MakeMove();
                    WhatToDoNext = WhatToDoNextAction.WaitingForAttackPoints;
                    break;

                case WhatToDoNextAction.WaitingForAttackPoints:
                    break;

                // ataque.
                case WhatToDoNextAction.Attack:
                    AttackNextPoint();
                    WhatToDoNext = WhatToDoNextAction.WaitingForPoints;
                    break;
            }
        }

        private void MakeMove()
        {
            if (this.PointsToVisit.Count > 0)
                this.MoveTo(PointsToVisit.Dequeue());
            else
                this.ForceAutoDestruction();
        }

        private void AttackNextPoint()
        {
            if (this.PointsToAttack.Count > 0)
                this.DefendTo(PointsToAttack.Dequeue(), 4);
            else
                this.ForceAutoDestruction();
        }
    }

    [Characteristics(ContainerCapacity = 0, CollectTransfertSpeed = 0, Scan = 5, MaxDamage = 5, DefenseDistance = 12, Constitution = 25)]
    public class Protector : VG.Common.NanoCollector, IActionable
    {
        public const int SquadNumber = 0;
        #region IAction Members
        public void DoActions()
        { }
        #endregion
    }
}
